package com.yfj.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.yfj.dao.CourseDao;
import com.yfj.dao.StudentDao;
import com.yfj.entity.Course;
import com.yfj.service.StudentService;

@Service
public class StudentServiceImpl implements StudentService {
	
	@Autowired
	private StudentDao studentDao;
	@Autowired
	private CourseDao courseDao;

	@Override
	@Transactional
	public void choseCourse(Long id, Long myId) {
		studentDao.addCourseStudent(id, myId);		//选课,向cs插值数据
		courseDao.addSelectedNum(id);			//更新course表selectedNum
	}
	
	@Override
	public List<Course> getMyCourse(Long myId) {
		List<Course> cList=studentDao.getCourseListByStudentId(myId);
		return cList;
	}
	
	@Override
	public void cancelCourse(Long id, Long myId) {
		studentDao.deleteCourseStudent(id, myId);
		courseDao.reduceSelectedNum(id);
	}
}
